package com.tsoj.context;

/**
 * ThreadLocal
 */
public class ThreadLocalContext {
    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();
    //设置userId给当前线程
    public static void setUserId(Long userId){
        threadLocal.set(userId);
    }
    //获得userId
    public static Long getUserId(){
        Long userId = threadLocal.get();
        System.out.println(userId);
        return userId;
    }
    //删除防止内存泄漏
    public static void remove(){
        threadLocal.remove();
    }
}
